package radar;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Vector;
import javax.swing.JPanel;

import logic.Coords2D;

import com.jme.renderer.ColorRGBA;
import editor.Grid;
import editor.Menu.OGGETTI;

public final class RadarPanel extends JPanel{
	private OGGETTI[][] cells;
	private Vector<PaintCell> paintCells;
	private static final long serialVersionUID = 210420101514L;
	public final static Color backGroundRadar = new Color(0,80,0);
	
	public RadarPanel()
	{
		super(true);
		paintCells = new Vector<PaintCell>();
		this.setBackground(backGroundRadar);
        this.setFocusable(true);
        this.setMinimumSize(new Dimension(256, 256));
        this.setPreferredSize(new Dimension(256, 256));
	}
	
	public final void getArena()
	{
		cells = Grid.getGrid();
		paintCells = new Vector<PaintCell>();
		for (int x=0;x<128;x++)
		{
			for (int y=0;y<128;y++)
			{
				switch(cells[x][y])
				{
				case PILL:			{paintCells.add(new PaintCell(x, y, Color.magenta.brighter()));break;}
				case EXTWALL: 		{paintCells.add(new PaintCell(x, y, Color.lightGray));break;}
				case WALL: 			{paintCells.add(new PaintCell(x, y, Color.white));break;}
				case RUBYBLUE: 		{paintCells.add(new PaintCell(x, y, Color.orange.darker()));break;}
				case RUBYGREEN:		{paintCells.add(new PaintCell(x, y, Color.orange));break;}
				case RUBYRED:		{paintCells.add(new PaintCell(x, y, Color.orange.brighter()));break;}
				case KEY:			{paintCells.add(new PaintCell(x, y, Color.cyan.brighter()));break;}
				}	
			}
		}
		drawMap();
	}
	
	public void setCell(ColorRGBA c, Coords2D p)
	{
		Graphics g = this.getGraphics();
		g.setColor(new Color(c.r, c.g, c.b));
		g.fillRect((int)p.getX()*2, (int)p.getY()*2, 2, 2);
	}
	
	public void setCell(Color c, Coords2D p)
	{
		System.out.println("EMPTY CELL ("+ p.toString() + ")");
		Graphics g = this.getGraphics();
		g.setColor(c);
		g.fillRect((int)p.getX()*2, (int)p.getY()*2, 2, 2);
	}
	
	public void drawMap()
	{
		Graphics g=this.getGraphics();
		PaintCell p=null;
		for(int i=0;i<paintCells.size();i++)
		{	
			p=paintCells.get(i);
			g.setColor(p.getColor());
			g.fillRect(p.getX()*2, p.getY()*2, 2, 2);
		}
	}
	
	@Override
	protected void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		g.setColor(Color.red);
		drawMap();
	}
}
